package com.shiliao.app.utils;

import android.content.Context;
import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.yimei.framework.util.LogUtil;


/**
 * Created by yinzhiqiang on 2017/10/19.
 */

public class MyWebView extends WebViewClient {
    private Context context;
    private String cotUrl;
    private Intent intent;
    private SwipeRefreshLayout refresh;
    private String refreshUrl;

    public MyWebView(WebView webView, Context context, String cotUrl, Intent intent,
                     SwipeRefreshLayout refresh, String refreshUrl) {
        this.context = context;
        this.cotUrl = cotUrl;
        this.intent = intent;
        this.refresh = refresh;
        this.refreshUrl = refreshUrl;
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        LogUtil.e("yzq", "..." + url);
        if (url.startsWith(cotUrl)) {
//            Intent intent = new Intent(context, activity.class);
            intent.putExtra("url", url);
            context.startActivity(intent);
            return true;
        }
        return false;
    }


    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        if (url.startsWith(refreshUrl)) {
            if (refresh != null) {
                refresh.setRefreshing(false);
            }
        }
    }

}
